package cn.lysj.framework.common.validate.validate;


import cn.lysj.framework.common.validate.annotation.Length;
import cn.lysj.framework.common.validate.entity.Entity;

public class LengthValidate extends AbstractValidate<Length> {

    public boolean validate(Entity entity) {
        if (null == entity.getValue()) return false;
        String arg = String.valueOf(entity.getValue());
        String min = String.valueOf(annotation.min());
        String max = String.valueOf(annotation.max());
        return arg.length() >= min.length() && arg.length() <= max.length();
    }

    public void init() {
        this.setMsg(annotation.message());
        this.setGroups(annotation.groups());
    }
}
